/*	Author: Ben Lovell
 *	<ben.j.lovell@gmail.com>
 *	This code is provided under the MIT licence. Check the licence file.
 *	Please contact me if you make anything cool/lame. I'd love to see :)
 *	Though obviously, you're under no obligation.
 */

function ignite ()
{
	var canvas = document.getElementById("graphCreator");
	var jscripted = document.getElementById("jscriptable");
	var coordinatePositions;
	
	//let's test this cursor shit out
	//canvas.addEventListener("click", graphOnClick(e), false);
	canvas.addEventListener("mousemove", 
	function(e) { 
	    	coordinatePositions = ("x:"+(e.clientX + canvas.scrollLeft - canvas.offsetLeft)
		+"\<br\>y:"+(e.clientY+canvas.scrollTop-canvas.offsetTop)); 
		jscripted.innerHTML = coordinatePositions;
     	}, false);	     	

    	if (canvas.getContext)	{
		var ctx = canvas.getContext('2d');
		canvasHeight = parseFloat(canvas.height);
		canvasWidth = parseFloat(canvas.width);
		ctx.clearRect(0,0,canvasWidth, canvasHeight);
		//grid
		if (document.getElementById("grid").checked)
		{
			ctx.beginPath();
			//the offset by 0.5 means that lines are 1px wide
			//if it were from 0, the px's either side would be drawn
			for (var x = 0.5; x < canvasWidth; x += 10)
			{	//left to right
				ctx.moveTo(x, 0);
				ctx.lineTo(x, canvasHeight);
			}
			for (var y = canvasHeight-0.5 ; y > 0; y -= 10)
			{	//bottom to top
				ctx.moveTo(0, y);
				ctx.lineTo(canvasWidth, y);
			}
			ctx.strokeStyle ="#eee";
			ctx.stroke();
			ctx.strokeStyle="#000";
		}
			
		//axes
		ctx.beginPath();
		ctx.moveTo(50,canvasHeight - 50);
		ctx.lineTo(50, 40);
		ctx.moveTo(50, canvasHeight - 50);
		ctx.lineTo(canvasWidth - 40, canvasHeight - 50);
		//ctx.strokeStyle="#000";
		ctx.lineWidth=4;
		ctx.lineCap="square";
		ctx.stroke();
		ctx.lineWidth=1;
	}
	
	
}

// Now this is just silly, come on html standards, you can do better!
function getCursorPosition(e, canvasref)	{
	var x;
	var y;
	x = e.clientx + canvasref.scrollLeft - canvasref.offsetLeft;
	y = e.clienty + canvasref.scrollTop - canvasref.offsetTop;
}
